﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YasharEl.Infrastructure.Transactions;

namespace YasharEl.Infrastructure.ServiceBus.Configuration
{
    public partial class TransactionTimeoutMustBeLessThanMaxTimeoutCallbackValidatorClass
    {
        public static void TransactionTimeoutMustBeLessThanMaxTimeout(object value)
        {
            TimeSpan? timeout = null;
            try
            {
                timeout = (TimeSpan)value;
            }
            catch
            {
                timeout = null;
            }

            if (timeout.HasValue)
            {
                if (timeout.Value > TransactionUtilities.GetMaxTransactionTimeout())
                {
                    throw new InvalidServiceBusConfigurationException(
                        "Timeout requested is longer than the maximum value for this machine. Please override using the maxTimeout setting of the system.transactions section in machine.config");
                }
            }
        }
    }
}
